package com.cmsr.springclond.common;

import java.util.Collections;

/**
 *
 * <description></description>
 * @project panda-framework
 * @author Johnny Liu
 * @date 2020-7-30
 *
 * @param <T>
 */
public class ResponseResult<T> extends ResponseBase {

	private T result;

	public ResponseResult() {}

	public ResponseResult(T data) {
		super(ResponseBase.SUCCESS_STATUS, ResponseBase.SUCCESS_MSG);
		this.result = data;
	}


	public ResponseResult(ResponseBase base, T data) {
		super(base.getStatus(), base.getMessages());
		this.result = data;
	}

	public ResponseResult(String status, String message) {
		super(status, message);
		this.result = null;
	}

	public ResponseResult(String status, String message, T data) {
		super(status, message);
		this.result = data;
	}

	public T getResult() {
		return result;
	}

	public void setResult(T data) {
		this.result = data;
	}

	@Override
	public String toString() {
		return "ResponseResult [result=" + result + "]";
	}

	public static<T> ResponseResult success(T data) {
		ResponseResult result=new ResponseResult(data);
		return result;
	}
	public static ResponseResult success() {
		ResponseResult result=new ResponseResult();
		result.setStatus(ResponseBase.SUCCESS_STATUS);
		result.setMessages(Collections.singletonList(ResponseBase.SUCCESS_MSG));
		result.result=null;
		return result;
	}

	public static <K> ResponseResult<K> APISuccess(K t) {
		ResponseResult<K> resp = new ResponseResult<>();
		resp.setStatus(ResponseBase.SUCCESS_STATUS);
		resp.setMessages(Collections.singletonList(ResponseBase.SUCCESS_MSG));
		resp.result = t;
		return resp;
	}

}
